﻿using SmartPlant.Model;
using SmartPlant.Model.Biz;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SmartPlant.Services.Interfaces
{
    /// <summary>
    /// 用户授权服务。对应administrator和intools user接口
    /// </summary>
    public interface IOAuthService
    {
        /// <summary>
        /// 切换服务器。即adminConn
        /// </summary>
        /// <param name="configId"></param>
        /// <returns></returns>
        Task<string> SwitchServerAsync(string configId);

        Task<List<ServerConfig>> GetConfigsAsync();

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="input">登录输入参数</param>
        /// <returns></returns>
        //Task<LoginOutput> TestLoginAsync(LoginInfo input);

        Task<string> GetServerInfoAsync(ServerInfo serverInfo);

        Task<RESTfulResult<string>> LoginAsync(LoginInfo loginInput);

        Task<List<UserRightData>> GetUserRightDatasAsync(string projId, string userId);

        Task<List<ServerConfig>> TestServerAsync(string serverAddress);


        #region User
        /// <summary>
        /// 查所有
        /// </summary>
        /// <returns></returns>
        Task<List<IntoolsUser>> GetAllUserList();


        /// <summary>
        /// 根据用户名查询用户
        /// </summary>
        /// <returns></returns>
        Task<IntoolsUser> GetUserByName(string userName);

        /// <summary>
        /// 根据用户名查询用户
        /// </summary>
        /// <returns></returns>
        Task<IntoolsUser> GetUserById(string userId);

        /// <summary>
        /// 根据Id删除用户
        /// </summary>
        /// <returns></returns>
        Task<bool?> DeleteUserById(string id);

        /// <summary>
        /// 更新用户
        /// </summary>
        /// <returns></returns>
        Task<bool?> UpdateUser(IntoolsUser user);

        /// <summary>
        /// 查所有
        /// </summary>
        /// <returns></returns>
        Task<bool?> CreateUser(IntoolsUser user);

        /// <summary>
        /// 获取《组》权限列表（所有unit）
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        Task<List<UserRightData>> GetGroup(string groupid);

        /// <summary>
        /// 权限分配（按Unit）
        /// </summary>
        /// <param name="data"></param>
        /// <param name="groupId"></param>
        /// <param name="unitId"></param>
        /// <returns></returns>
        Task<bool?> SetGroup(List<UserRightData> data, string groupId, string unitId);

        /// <summary>
        /// 权限分配（all）
        /// </summary>
        /// <param name="data"></param>
        /// <param name="groupId"></param>
        /// <param name="unitId"></param>
        /// <returns></returns>
        Task<bool?> SetGlobalGroup(int access, string groupId);

        #endregion

        #region UserGroup
        /// <summary>
        /// 查所有
        /// </summary>
        /// <returns></returns>
        Task<bool?> CreateUserGroupr(UserGroup user);

        /// <summary>
        /// 查所有
        /// </summary>
        /// <returns></returns>
        Task<bool?> UpdateUserGroupr(UserGroup user);

        /// <summary>
        /// 查所有
        /// </summary>
        /// <returns></returns>
        Task<bool?> DeleteUseGrouprById(string id);

        /// <summary>
        /// 根据用户名查询用户
        /// </summary>
        /// <returns></returns>
        Task<UserGroup> GetUserGroupById(string id);

        /// <summary>
        /// 查所有
        /// </summary>
        /// <returns></returns>
        Task<List<UserGroup>> GetAllUserGroupList();

        /// <summary>
        /// 分配到用户组（原则上一个用户只属于一个用户组）
        /// </summary>
        /// <returns></returns>
        Task<bool?> AssignToGroup(string userId, string groupId);

        /// <summary>
        /// 从用户组中移除
        /// </summary>
        /// <returns></returns>
        Task<bool?> UnAssignFromGroup(string userId, string groupId);
        #endregion
    }
}
